/***********************************************************************
 * Module:  ProcedureCabinet.java
 * Author:  Vanil
 * Purpose: Defines the Class ProcedureCabinet
 ***********************************************************************/
package hosp;
import db.dao.OperationDao;
import db.dao.ProcedurecabinetDao;
import db.dto.OperationDto;
import db.dto.ProcedurecabinetDto;
import db.exceptions.OperationDaoException;
import db.exceptions.ProcedurecabinetDaoException;
import db.jdbc.OperationDaoImpl;
import db.jdbc.ProcedurecabinetDaoImpl;
import process.Operation;

import java.util.ArrayList;
import java.util.Collection;

public class ProcedureCabinet {
    ProcedurecabinetDto dto;

    public ProcedureCabinet(ProcedurecabinetDto dto) {
        this.dto = dto;
    }

    private void updateUpload() throws ProcedurecabinetDaoException {
        ProcedurecabinetDao dao = new ProcedurecabinetDaoImpl();
        dao.update(dto.getNumber(),dto);
    }
    public ProcedurecabinetDto getDto() {
        return dto;
    }
    public void setDepartment(Department dep) throws ProcedurecabinetDaoException {
        dto.setIdDepartment(dep.getIdDepartment());
        updateUpload();
    }


   public java.util.Collection<Operation> getOperations() throws OperationDaoException {
        OperationDao dao = new OperationDaoImpl();
        OperationDto[] operationDtos = dao.findByProcedurecabinet(dto.getNumber());
        Collection<Operation> list = new ArrayList<Operation>();
        for(OperationDto opDto:operationDtos)
            list.add(new Operation(opDto));
        return list;

    }

}